package com.gs.core.web.controllers;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.ModelAndView;

import com.gs.core.domain.User;
import com.gs.core.service.UserService;

@Controller
@RequestMapping("/user")
public class UserController {
	
	@Autowired
	UserService userService;
	
	@RequestMapping("/userDetails/{id}")
	public String getUser(@PathVariable String id, Model model){
		User user = userService.get(id);
		model.addAttribute(user);
		return "userDetails";
	}
	@RequestMapping("/users")
	public String findAll(Model model){
		model.addAttribute("users", userService.findAll());
		return "userList";
	}
	
	@RequestMapping(value="/details/{id}")	
	public @ResponseBody User get(@PathVariable String id){
		User user = userService.get(id);
		return user;
	}
	@RequestMapping(value="/all")	
	public @ResponseBody Collection<User> get(){
		return userService.findAll();
	}
	
}
